import 'package:duuchin/components/avatar_role_name.dart';
import 'package:duuchin/components/comment_like_read.dart';
import 'package:duuchin/config/app_colors.dart';
import 'package:duuchin/models/song_model.dart';
import 'package:duuchin/utils/util.dart';
import 'package:flutter/material.dart';

class SongCardPage extends StatelessWidget {
  final SongItem songItem;

  const SongCardPage({Key key, this.songItem}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(top: 10),
      padding: EdgeInsets.all(toRpx(context, 30)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          _songCover(),
          SizedBox(width: 10),
          _songContent(),
        ],
      ),
    );
  }

  Widget _songContent() {
    return Expanded(
        flex: 1,
        child: SizedBox(
          height: 75,
          child: Stack(
            children: <Widget>[
              Text(
                songItem.cnName,
                style: TextStyle(
                  color: AppColors.active,
                  fontSize: 15,
                ),
                maxLines: 1,
                overflow: TextOverflow.ellipsis,
              ),
              Positioned(
                  top: 25,
                  child: Text(
                    songItem.enName,
                    style: TextStyle(
                      color: AppColors.un3active,
                      fontSize: 14,
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  )),
              Align(
                alignment: Alignment.bottomLeft,
                child: Row(
                  children: <Widget>[
                    SizedBox(
                      width: 100,
                      child: AvatarRoleName(
                        coverPictureUrl: songItem.user.coverPictureUrl,
                        nikename: songItem.user.nickname,
                        type: 'ADMIN',
                        showType: true,
                      ),
                    ),
                    SizedBox(width: 5),
                    CommentLikeRead(
                      commentCount: songItem.commentCount,
                      thumbUpCount: songItem.thumbUpCount,
                      readCount: songItem.readCount,
                    )
                  ],
                ),
              ),
            ],
          ),
        ));
  }

  // 封面的组件信息
  Widget _songCover() {
    return SizedBox(
      width: 75,
      height: 75,
      child: Stack(
        fit: StackFit.expand,
        children: <Widget>[
          ClipRRect(
            borderRadius: BorderRadius.circular(10),
            child: FadeInImage.assetNetwork(
              placeholder: 'assets/images/common/lazy-1.png',
              image: songItem.coverPictureUrl,
              fit: BoxFit.cover,
            ),
          ),
          Center(
            child: Image.asset(
              'assets/images/icons/tiny_video.png',
              width: 24,
              height: 24,
              color: Colors.white,
            ),
          )
        ],
      ),
    );
  }
}
